package com.example.pet.service;

import com.example.pet.dao.UserInfoDao;
import com.hj.pet.api.UserInfoService;
import com.hj.pet.constant.Code;
import com.hj.pet.model.ReturnT;
import com.hj.pet.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoServiceImp implements UserInfoService {
    @Autowired
    UserInfoDao userInfoDao;
    @Override
    public int save(UserInfo userInfo){
        System.out.println(userInfo);
        return userInfoDao.save(userInfo);
    }

    @Override
    public int updateById(UserInfo userInfo){
        System.out.println(userInfo);
        return userInfoDao.updateById(userInfo);
    }

    @Override
    public UserInfo findUserById(int userId){
        return userInfoDao.findUserById(userId);
    }

    @Override
    public UserInfo findUserByAc(String user_account){
        return userInfoDao.findUserByAc(user_account);
    }

    @Override
    public List<UserInfo> findUsersSeller(boolean is_seller){
        return userInfoDao.findUsersSeller(is_seller);
    }


    @Override
    public List<UserInfo> findUsersVip(boolean is_vip){
        return userInfoDao.findUsersVip(is_vip);
    }


    @Override
    public int delUserById(int userId){
        return userInfoDao.delUserById(userId);
    }

    @Override
    public List<UserInfo> findUsers(UserInfo userInfo){
        return userInfoDao.findUsers(userInfo);
    }

    @Override
    public ReturnT<?> addUserInfo(UserInfo userInfo){
        if(0== userInfoDao.searchByUserAccount(userInfo.getUser_account())){
            ReturnT returnT= ReturnT.errorReturn;
            returnT.setMsg("该用户还没注册");
            return returnT;
        }
        if (0<userInfoDao.save(userInfo)){
            return new ReturnT<>(Code.SUCCESS, "申请成功，等待验证");
        } else {
            return ReturnT.errorReturn;
        }
    }
}
